[−][src]Crate tract_core
Tract
Tiny, no-nonsense, self contained, portable TensorFlow and ONNX inference.
Example
use tract_core::internal::*; // build a simple model that just add 3 to each input component let mut model = InferenceModel::default(); let input = model.add_source_default("input").unwrap(); let three = model.add_const("three".to_string(), tensor0(3f32)).unwrap(); let add = model.add_node_default("add".to_string(), tract_core::ops::math::Add::default(), ).unwrap(); model.add_edge(OutletId::new(input, 0), InletId::new(add, 0)).unwrap(); model.add_edge(OutletId::new(three, 0), InletId::new(add, 1)).unwrap(); // We build an execution plan. Default inputs and outputs are inferred from // the model graph. let plan = SimplePlan::new(&model).unwrap(); // run the computation. let input = ndarray::arr1(&[1.0f32, 2.5, 5.0]); let mut outputs = plan.run(tvec![input.into()]).unwrap(); // take the first and only output tensor let mut tensor = outputs.pop().unwrap(); // unwrap it as array of f32 let tensor = tensor.to_array_view::<f32>().unwrap(); assert_eq!(tensor, ndarray::arr1(&[4.0, 5.5, 8.0]).into_dyn());
While creating a model from Rust code is useful for testing the library, real-life use-cases will usually load a TensorFlow or ONNX model using tract-tensorflow or tract-onnx crates.
Re-exports
pub extern crate error_chain; |
pub extern crate ndarray; |
pub use crate::errors::*; |
Modules
analyser | |
broadcast | |
datum |
|
dim | |
errors | error_chain generated types |
framework | |
internal | This prelude is meant for code extending tract (like implementing new ops). |
macros | |
model | Models and their lifecycle |
ops | Ops |
plan | |
prelude | This prelude is meant for code using tract. |
pulse | |
tensor |
|
Macros
args_1 | |
args_2 | |
args_3 | |
args_4 | |
args_5 | |
assert_backward | Asserts that backward inference results work as expected. |
assert_close | |
assert_forward | Asserts that forward inference results work as expected. |
boxed_new | |
dimfact | Constructs a dimension fact. |
dispatch_copy | |
dispatch_datum | |
dispatch_floatlike | |
dispatch_numbers | |
element_bin | |
element_map | |
element_map_with_params | |
impl_op_same_as | |
shapefact | Constructs a shape fact. |
tvec | |
typefact | Constructs a type fact. |
unwrap_or_none | Tries to unwrap an option, or returns Ok(None) otherwise. |
valuefact | Constructs an value fact. |
wrap |